package com.sa.spring.web.control;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.sa.spring.service.BookService;


public class BookQueryController extends AbstractController{
	
	private BookService bookService;
	
	public void setBookService(BookService bookService){
		this.bookService = bookService;
	}

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		String title = ServletRequestUtils.getStringParameter(request, "title");
		Map<String,Object> model = new HashMap<String,Object>();
		if(title != null){
			model.put("title", title);
			model.put("bookCount",bookService.queryByTitle(title));
		}
		return new ModelAndView("bookQuery",model);//"bookQuery" is the redirect Website name
	}

}
